#include <REGX52.H>

int count=0;
int time=0;
int state=0;
void timer0_init()
{
    TMOD &= 0xF0;
    TMOD |= 0x01;

    TH0 = 0x3C;

    TL0 = 0xB0;

    TR0 = 0;

    ET0 = 1;

    EA = 1;
    
    PT0 = 1;
}

void timer0_ISR() interrupt 1
{
    
    TH0 = 0x3C;
    TL0 = 0xB0;

    time = time + 1;
    if(time==20)
    {
     state=state+1;
     time=0;
    }
    if(P2_6==0)
    {
       while(P2_6==0){}
       count++;
    }
}

void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}

void main()
{
    int i;
    timer0_init();
    P2_0=0;
    while(1)
    {
     if(P2_6==0)
     {
       while(P2_6==0){}
       count++;
     }
     if(count==1)
     {
      P2_0=1;
      TR0 =1;
     }
     if(count>=2)
     {
      TR0=0;
      for(i=1;i<=state;i++)
      {
       P2_0=1;
       delay_ms(500);
       P2_0=0;
       delay_ms(500);
      }
      count=0;
     }
     }
}